import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class CodeCounter {

	/**
	 * @Title: main
	 * @Description: TODO(这里用一句话描述这个方法的作用)
	 * @param @param args 设定文件
	 * @return void 返回类型
	 * @throws
	 */

	static long normalLines = 0;
	static long commentLines = 0;
	static long whiteLines = 0;

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		File f = new File(
				"D:\\Users\\msirene\\Workspaces\\MyEclipse 10\\slowlookrtm\\src\\com\\cctcq\\action");
		File[] codeFiles = f.listFiles();
		for (File child : codeFiles) {
			if (child.getName().matches(".*\\.java$")) {
				parse(child);
			}

		}
		System.out.println("action:" + normalLines);
		System.out.println("action注释:" + commentLines);
		System.out.println("action空行:" + whiteLines);
	}

	private static void parse(File f) {
		BufferedReader br = null;
		boolean comment = false;
		try {
			br = new BufferedReader(new FileReader(f));
			String line = "";
			while ((line = br.readLine()) != null) {
				line = line.trim();
				if (line.matches("^[\\s&&[^\\s]]*$")) {
					whiteLines++;
				} else if (line.startsWith("/*") && !line.endsWith("*/")) {
					commentLines++;
					comment = true;
				} else if (line.startsWith("/*") && !line.endsWith("*/")) {
					commentLines++;
				} else if (true == comment) {
					commentLines++;
					if (line.endsWith("*/")) {
						comment = false;

					}
				} else if (line.startsWith("//")) {
					commentLines++;
				} else {
					normalLines++;
				}
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			if (br != null) {
				try {
					br.close();
					br = null;
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

}
